/* ERR */

#include <stdio.h>
#include <stdlib.h>

typedef struct AVLTree* PtrToATree;
struct AVLTree {
    int data;
    PtrToATree left;
    PtrToATree right;
    int height;
};
typedef PtrToATree AVLTree;

int max ( int a, int b ) {
    return ( a > b ? a : b );
}

int Getheight ( AVLTree T ) {
    int LH, RH, maxh = 0;
    if ( T ) {
        LH = Getheight(T->left);
        RH = Getheight(T->right);
        maxh = max(LH,RH);
        return ( maxh + 1 );
    } else return 0;
}

AVLTree SingleLeftRotation ( AVLTree A ) {
    AVLTree B = A->left;
    A->left = B->right;
    B->right = A;
    A->height = max( Getheight(A->left), Getheight(A->right) ) + 1;
    B->height = max( Getheight(B->left), Getheight(B->right) ) + 1;
    return B;
}

AVLTree SingleRightRotation ( AVLTree A ) {
    AVLTree B = A->right;
    A->right = B->left;
    B->left = A;
    A->height = max( Getheight(A->left), Getheight(A->right) ) + 1;
    B->height = max( Getheight(B->left), Getheight(B->left) ) + 1;
    return B;
}

AVLTree DoubleLeftRightRotation ( AVLTree A ) {
    A->left = SingleRightRotation(A->left);
    return SingleLeftRotation(A);
}

AVLTree DoubleRightLeftRotation ( AVLTree A ) {
    A->right = SingleLeftRotation(A->right);
    return SingleRightRotation(A);
}

AVLTree Insert ( AVLTree T, int X ) {
    if ( !T ) {
        T = (AVLTree)malloc(sizeof(struct AVLTree));
        T->data = X;
        T->left = T->right = NULL;
        T->height = 0;
    } else {
        if ( X > T->data ) {
            T->right = Insert( T->right, X );
            if ( Getheight(T->left) - Getheight(T->right) == -2 ) {
                if ( X > T->right->data ) T = SingleRightRotation(T);
                else T = DoubleRightLeftRotation(T);
            }
        } else if ( X < T->data ) {
            T->left = Insert( T->left, X );
            if ( Getheight(T->left) - Getheight(T->right) == 2 ) {
                if ( X > T->left->data ) T = DoubleLeftRightRotation(T);
                else T = SingleLeftRotation(T);
            }
        }
    }
    T->height = max( Getheight(T->left), Getheight(T->right) ) + 1;
    return T;
}

void free_tree ( AVLTree T ) {
    if ( T ) {
        free_tree(T->left);
        free(T);
        free_tree(T->right);
    }
}

int main () {
    int N, X, i;
    AVLTree T = NULL;
    scanf("%d", &N);
    for ( i = 0; i < N; i++ ) {
        scanf("%d", &X);
        T = Insert(T,X);
    }
    printf("%d\n", T->data);
    free_tree(T);
    return 0;
}